package com.snlab;

public class Rule implements Comparable<Rule>{
    private final long match;
    private final int prefix;
    private final Port outPort;
    private final Device device;

    private int hit;

    public Rule(Device device, long ipv4, int prefix, Port outPort) {
        this.device = device;
        this.match = ipv4;
        this.prefix = prefix;
        this.outPort = outPort;
    }

    @Override
    public int compareTo(Rule r) {
        if (r.getPriority() > this.getPriority()) {
            return -1;
        } else if (r.getPriority() > this.getPriority()) {
            return 1;
        } else {
            return 0;
        }
    }

    public Device getDevice() {
        return device;
    }

    public long getMatch() {
        return match;
    }

    public int getHit() {
        return hit;
    }

    public void setHit(int hit) {
        this.hit = hit;
    }

    public int getPrefix() {
        return prefix;
    }

    public Port getOutPort() {
        return outPort;
    }

    public int getPriority() {
        return prefix;
    }
}

